package org.summer.lawyer.controller.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.summer.common.core.domain.R;
import org.summer.common.core.validate.AddGroup;
import org.summer.common.core.validate.EditGroup;
import org.summer.common.excel.utils.ExcelUtil;
import org.summer.common.idempotent.annotation.RepeatSubmit;
import org.summer.common.log.annotation.Log;
import org.summer.common.log.enums.BusinessType;
import org.summer.common.mybatis.core.page.PageQuery;
import org.summer.common.mybatis.core.page.TableDataInfo;
import org.summer.common.web.core.BaseController;
import org.summer.lawyer.domain.bo.paytransfer.PayTransferBo;
import org.summer.lawyer.domain.vo.paytransfer.PayTransferVo;
import org.summer.lawyer.service.IPayTransferService;

import java.util.List;

/**
 * 转账单
 *
 * @author summer
 * @date 2024-06-23
 */
@Tag(name = "后台相关接口", description = "转账相关接口")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/lawyer/payTransfer")
public class PayTransferController extends BaseController {

    private final IPayTransferService payTransferService;

    /**
     * 查询转账单列表
     */
    @Operation(summary = "查询转账单列表接口", description = "查询转账单列表", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    @SaCheckPermission("lawyer:transfer:list")
    @GetMapping("/list")
    public TableDataInfo<PayTransferVo> list(PayTransferBo bo, PageQuery pageQuery) {
        return payTransferService.selectPageList(bo, pageQuery);
    }

    /**
     * 导出转账单列表
     */
    @Operation(summary = "导出转账单列表接口", description = "导出转账单列表")
    @SaCheckPermission("lawyer:transfer:export")
    @Log(title = "转账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PayTransferBo bo, HttpServletResponse response) {
        List<PayTransferVo> list = payTransferService.selectPayTransferVoList(bo);
        ExcelUtil.exportExcel(list, "转账单", PayTransferVo.class, response);
    }

    /**
     * 获取转账单详细信息
     *
     * @param id 主键
     */
    @Operation(summary = "获取转账单详细信息接口", description = "查询转账单列表", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    @SaCheckPermission("lawyer:transfer:query")
    @GetMapping("/{id}")
    public R<PayTransferVo> getInfo(@NotNull(message = "主键不能为空")
                                    @PathVariable Long id) {
        return R.ok(payTransferService.selectPayTransferVoById(id));
    }

    /**
     * 新增转账单
     */
    @Operation(summary = "新增转账单接口", description = "新增转账单", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    @SaCheckPermission("lawyer:transfer:add")
    @Log(title = "转账单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/savePayTransfer")
    public R<Void> savePayTransfer(@Validated(AddGroup.class) @RequestBody PayTransferBo bo) {
        return toAjax(payTransferService.insertByBo(bo));
    }

    /**
     * 修改转账单
     */
    @Operation(summary = "修改转账单接口", description = "修改转账单", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    @SaCheckPermission("lawyer:transfer:edit")
    @Log(title = "转账单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/updatePayTransfer")
    public R<Void> updatePayTransfer(@Validated(EditGroup.class) @RequestBody PayTransferBo bo) {
        return toAjax(payTransferService.updateByBo(bo));
    }

    /**
     * 删除转账单
     *
     * @param ids 主键串
     */
    @Operation(summary = "删除转账单接口", description = "删除转账单", responses = { @ApiResponse( responseCode = "200", description = "成功")})
    @SaCheckPermission("lawyer:transfer:remove")
    @Log(title = "转账单", businessType = BusinessType.DELETE)
    @DeleteMapping("/removePayTransfer/{ids}")
    public R<Void> removePayTransfer(@NotEmpty(message = "主键不能为空")
                                     @PathVariable Long[] ids) {
        return toAjax(payTransferService.deleteWithValidByIds(List.of(ids), true));
    }
}
